package com.lzh.others.basejava.Thread_21;

import org.apache.commons.lang3.RandomUtils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @Classname SleepTask
 * @Description 休眠方法
 * @Date 2021/9/14 10:43
 * @Created by liuzihao
 */
public class SleepingTask extends LiftOff{
    @Override
    public void run() {
        try {
            while (countDown-- > 0) {
                System.out.println(status());
                int i = RandomUtils.nextInt(500, 2000);
                System.out.println("休眠了" + TimeUnit.MILLISECONDS.toMillis(i) + "毫秒");
                TimeUnit.MILLISECONDS.sleep(i);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 5; i++) {
            executorService.execute(new SleepingTask());
        }
        executorService.shutdown();
        System.out.println(TimeUnit.HOURS.toDays(24));
    }
}
